/*
	FileName : BSP_SPI.h
	Description :
		
	
	Created on 2013.10.14 by ZZP.
	
	Revision History:
	

*/

#ifndef __BSP_SPI_H__
#define __BSP_SPI_H__

#include "stdint.h"


////////////////////////////////////////////////////////////////////////////
///	Constants: PINs and clocks
////////////////////////////////////////////////////////////////////////////
#define SPIx							SPI2
///MODULE CLK
#define SPIx_CLK_ENABLE()				__HAL_RCC_SPI2_CLK_ENABLE()
#define SPIx_CLK_DISABLE()				__HAL_RCC_SPI2_CLK_DISABLE()

#define SPIx_FORCE_RESET()				__HAL_RCC_SPI2_FORCE_RESET()
#define SPIx_RELEASE_RESET()			__HAL_RCC_SPI2_RELEASE_RESET()

///CLK PIN
#define SPIx_CLK_PIN                    GPIO_PIN_12
#define SPIx_CLK_GPIO_PORT              GPIOA
#define SPIx_CLK_AF                     GPIO_AF5_SPI2
#define SPIx_CLK_GPIO_CLK_ENABLE()		__HAL_RCC_GPIOA_CLK_ENABLE()

///MISO PIN
#define SPIx_MISO_PIN                   GPIO_PIN_14
#define SPIx_MISO_GPIO_PORT             GPIOB
#define SPIx_MISO_AF                    GPIO_AF5_SPI2
#define SPIx_MISO_GPIO_CLK_ENABEL()		__HAL_RCC_GPIOB_CLK_ENABLE()

///MOSI PIN
#define SPIx_MOSI_PIN                   GPIO_PIN_1
#define SPIx_MOSI_GPIO_PORT             GPIOC
#define SPIx_MOSI_AF                    GPIO_AF5_SPI2
#define SPIx_MOSI_GPIO_CLK_ENABEL()		__HAL_RCC_GPIOC_CLK_ENABLE()

///NSS PIN
#define SPIx_NSS_PIN					GPIO_PIN_11
#define SPIx_NSS_GPIO_PORT				GPIOA
#define SPIx_NSS_AF						GPIO_AF5_SPI2
#define SPIx_NSS_GPIO_CLK_ENABEL()		__HAL_RCC_GPIOA_CLK_ENABLE()

///IRQ PIN
#define SPIx_IRQ_PIN					GPIO_PIN_3
#define SPIx_IRQ_GPIO_PORT				GPIOD
#define SPIx_IRQ_GPIO_CLK_ENABEL()		__HAL_RCC_GPIOD_CLK_ENABLE()

///Interrupt
#define SPIx_IRQn                    	SPI2_IRQn
#define SPIx_IRQHandler              	SPI2_IRQHandler
#define SPIx_INT_PRIO					SPI2_INT_PRIO
#define SPIx_EXTI_IRQn					EXTI3_IRQn
#define SPIx_EXTI_INT_PRIO				EXTI3_INT_PRIO
#define SPIx_EXTI_IRQHandler			EXTI3_IRQHandler

///DMA
#define SPIx_DMA_TX_CHANNEL				DMA_REQUEST_SPI2_TX
#define SPIx_DMA_RX_CHANNEL				DMA_REQUEST_SPI2_RX

////////////////////////////////////////////////////////////////////////////
///				Global function prototypes
////////////////////////////////////////////////////////////////////////////
void BSP_SPIx_Init(void);
void BSP_SPIx_DeInit(void);

void BSP_SPIx_EnableEXTI(void);
void BSP_SPIx_DisableEXTI(void);

/*
Params:
	TxBuf:		Transmit data buffer
	RxBuf:		Receive data buffer
	len:		Transmit and receive data len
return:
	0-------	OK
	other---	error
*/
uint8_t BSP_SPIx_ReadWrite(uint8_t *TxBuf, uint8_t *RxBuf, uint16_t len);

/*
Params:
	None
return:
	0-------	not ready
	1-------	ready
*/
uint8_t BSP_SPIx_GetStatus(void);

#endif///





